//
//  IDrink.m
//  XRmenu
//
//  Created by yangxh on 11-3-24.
//  Copyright 2011 E0571. All rights reserved.
//

#import "IDrink.h"


@implementation IDrink

@synthesize capacity;
@synthesize drinkId;
@synthesize Id;
@synthesize name;
@synthesize place;
@synthesize precision;
@synthesize temperature;
@synthesize year;
@synthesize spellCode;

//=========================================================== 
// - (id)init
//
//=========================================================== 
- (id)init
{
	return [self initWithCapacity:nil drinkId:nil Id:0 name:nil place:nil precision:nil temperature:nil year:nil];
}


//=========================================================== 
// - (id)initWith:
//
//=========================================================== 
- (id)initWithCapacity:(NSString*)aCapacity drinkId:(NSString*)aDrinkId Id:(NSInteger)anId name:(NSString*)aName place:(NSString*)aPlace precision:(NSString*)aPrecision temperature:(NSString*)aTemperature year:(NSString*)aYear 
{
    self = [super init];
    if (self) {
        self.capacity = aCapacity;
        self.drinkId = aDrinkId;
        self.Id = anId;
        self.name = aName;
        self.place = aPlace;
        self.precision = aPrecision;
        self.temperature = aTemperature;
        self.year = aYear;
    }
    return self;
}


//=========================================================== 
// + (id)objectWith:
//
//=========================================================== 
+ (id)objectWithCapacity:(NSString*)aCapacity drinkId:(NSString*)aDrinkId Id:(NSInteger)anId name:(NSString*)aName place:(NSString*)aPlace precision:(NSString*)aPrecision temperature:(NSString*)aTemperature year:(NSString*)aYear  
{
    id result = [[[self class] alloc] initWithCapacity:aCapacity drinkId:aDrinkId Id:anId name:aName place:aPlace precision:aPrecision temperature:aTemperature year:aYear];
	
    return [result autorelease];
}

//=========================================================== 
// - (NSArray *)keyPaths
//
//=========================================================== 
- (NSArray *)keyPaths
{
    NSArray *result = [NSArray arrayWithObjects:
					   @"capacity",
					   @"drinkId",
					   @"Id",
					   @"name",
					   @"place",
					   @"precision",
					   @"temperature",
					   @"year",
					   @"spellCode",
					   nil];
	
    return result;
}


//=========================================================== 
// - (NSString *)descriptionForKeyPaths
//
//=========================================================== 
- (NSString *)descriptionForKeyPaths 
{
    NSMutableString *desc = [NSMutableString string];
    NSEnumerator *e = [[self keyPaths] objectEnumerator];
    NSString *thisKey;
    [desc appendString:@"\n\n"];
	
    while ((thisKey = [e nextObject])) {
        [desc appendFormat: @"%@: %@\n", thisKey, [self valueForKey:thisKey]];
    }
	
    return [NSString stringWithString:desc];
}

- (NSString *)description
{
	return [self descriptionForKeyPaths];
}

//=========================================================== 
// dealloc
//=========================================================== 
- (void)dealloc
{
    [capacity release];
    capacity = nil;
    [drinkId release];
    drinkId = nil;
    [name release];
    name = nil;
    [place release];
    place = nil;
    [precision release];
    precision = nil;
    [temperature release];
    temperature = nil;
    [year release];
    year = nil;
	[spellCode release];
	spellCode = nil;
	
    [super dealloc];
}

+ (IDrink *)iDrinkByParse:(NSDictionary *)info
{
	IDrink *drink = [IDrink objectWithCapacity:dictObject(info,@"Capacity")
									   drinkId:dictObject(info,@"DrinkId")
											Id:dictInt(info,@"ID")
										  name:dictObject(info,@"Name")
										 place:dictObject(info,@"Place")
									 precision:dictObject(info,@"Precision")
								   temperature:dictObject(info,@"Temperature")
										  year:dictObject(info,@"Year")];
	drink.spellCode = dictObject(info,@"SpellCode");
	return drink;
}

@end
